package com.wcs.exam.dao.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.wcs.exam.common.base.page.SqlUtil;
import com.wcs.exam.dao.UserAttendanceDao;
import com.wcs.exam.dao.impl.mapper.entity.UserAttendance;
import com.wcs.exam.dao.impl.mapper.UserAttendanceMapper;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 用户考勤 持久化实现类
 *
 * @author wcs
 * @since 2025-03-13
 */
@Repository
public class UserAttendanceDaoImpl extends ServiceImpl<UserAttendanceMapper, UserAttendance> implements UserAttendanceDao {

    @Override
    public <R> List<R> selectObjs(Wrapper<UserAttendance> wrapper, Class<R> classType) {
        List<Map<String, Object>> resultMaps = baseMapper.selectMaps(wrapper);
        if (CollectionUtil.isEmpty(resultMaps)) {
            return Collections.emptyList();
        }
        return BeanUtil.copyToList(resultMaps, classType);
    }

    @Override
    public Integer getMaxSort() {
       return lambdaQuery().orderByDesc(UserAttendance::getSort).last(SqlUtil.limitOne()).oneOpt().map(UserAttendance::getSort).orElse(0);
    }
}
